package com.example.myfirstapp;

import com.parse.*;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class SignInFragment extends Fragment{
	@Override
	public View onCreateView( LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState )
	{
		View view = inflater.inflate( R.layout.frag_signin, container, false );
		
		Button buttonSignup = (Button) view.findViewById(R.id.button_signin);
		buttonSignup.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				signin(v);
			}
        });
		
		return view;
	}
	
	public void signin(View v){
		EditText editText = (EditText) getView().findViewById(R.id.edit_username);
    	String username = editText.getText().toString();
    	 
    	editText = (EditText) getView().findViewById(R.id.edit_password);
    	String password = editText.getText().toString();
    
    	//validate inputs first then continue
		username = "gmertk";
    	password = "12345";
    	
    	ParseUser.logInInBackground(username, password, new LogInCallback() {
			public void done(ParseUser user, ParseException e) {
				if (user != null) {
					Intent i = new Intent(getActivity(),HomeActivity.class);
				
					startActivity(i);
				} else {
    	    		Log.e("signin error in parse", e.getCode()+"");

			    }
			}
		});
	}
}
